import java.util.HashMap;
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;

public class Demo_CountDownLatch {
    public static int count = 0;
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        //await会在调用10次countDown后执行
        for(int i = 0; i < 10; i++){
            int id = i;
            Thread t = new Thread(() -> {
                System.out.println("thread" + id);
                for(int j = 0; j < 1000; j++){
                    count++;
                }
                //完成一个任务，就通知一次
                countDownLatch.countDown();
            });
            t.start();
        }
        //所有任务都完成了，就通知
        countDownLatch.await();
        System.out.println("count = " + count);
        System.out.println("所有任务都完成了");
    }
}
